<template>
<div class="switchBase">
    <label class="switch">
        <input :checked="prop.value" type="checkbox" @change="(e) => handleChange(e)">
        <span class="slider"></span>
    </label>
</div>
</template>

<script lang="ts" setup>
import { ref, defineEmits, defineProps } from "vue"
import useAppStore from '@/pinia'
const app = useAppStore()
const handleChange = (e) => {
    app.playSound('audio11')
    emit('change', e.target.checked)
}

const prop = defineProps(['value'])
const emit = defineEmits(['change'])

</script>

<style lang="scss">
.switchBase {
    box-sizing: border-box;
    .input {
        visibility: hidden;
        display: none;
    }

    &::after, &::before {
        box-sizing: border-box;
    }

    .switch {
        font-size: 1rem;
        position: relative;
        display: inline-block;
        width: 4em;
        height: 2em;
    }

    .slider {
        position: absolute;
        cursor: pointer;
        inset: 0;
        background-color: #eee;
        transition: 0.4s;
        border-radius: 0.5em;
        box-shadow: 0 0.2em #dfd9d9;
    }

    .slider:before {
        position: absolute;
        content: "";
        height: 1.5em;
        width: 1.4em;
        border-radius: 0.3em;
        left: 0.3em;
        bottom: 0.7em;
        background-color: lightsalmon;
        transition: 0.4s;
        box-shadow: 0 0.4em #bcb4b4;
    }

    .slider:hover::before {
        box-shadow: 0 0.2em #bcb4b4;
        bottom: 0.5em;
    }

    input:checked + .slider::before {
        transform: translateX(2em);
        background: lightgreen;
    }
}
</style>